package com.tmt.paymentcenter.web.domain;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 交易详情记录。
 */
@Getter
@Setter
@Entity
@EntityListeners({AuditingEntityListener.class})
public class TradeDetailHistory extends BaseCreator implements Serializable {

    /**
     * 交易金额
     */
    @Column(nullable = false)
    private BigDecimal amount;

    /**
     * 支付人
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, optional = false)
    @JoinColumn(name="outUser_id", nullable = false)
    private TradeUser outUser;

    /**
     * 支付帐号
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, optional = false)
    @JoinColumn(name="outAccount_id", nullable = false)
    private Account outAccount;

    /**
     * 收钱人
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, optional = false)
    @JoinColumn(name="inUser_id", nullable = false)
    private TradeUser inUser;

    /**
     * 收入账户
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, optional = false)
    @JoinColumn(name="inAccount_id", nullable = false)
    private Account inAccount;

    /**
     * 关联的交易记录
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, optional = false)
    @JoinColumn(name="tradeHistory_id", nullable = false)
    private TradeHistory tradeHistory;

    /**
     * 关联的资金变动记录
     */
    @OneToOne(mappedBy = "tradeDetailHistory")
    private AccountChangeHistory accountChangeHistory;
}
